home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / shelf.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  10.0 KB  |  348 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File
  19. // MODIFY THIS AT YOUR OWN RISK
  20. //
  21. // Creation Date: 1995
  22. //
  23. // Description:
  24. //        This implements the group of controls that represents the
  25. //        shelf.  The shelf can either be part of a window
  26. //        or in a window of its own.
  27. //
  28. // Input Arguments:
  29. //        The name of the layout that the shelf should add itself
  30. //        to.  If empty, then this script will create a window.
  31. //
  32. // Return Value:
  33. //        The name of the top level layout control.
  34. //            (Used for embedding within another window)
  35. //
  36.  
  37. global proc buildShelfMenu( string $parent ) 
  38. //    
  39. //    Create the popup menu that allows users to switch between
  40. //    shelf tabs.  This is created each time it is selected to
  41. //    keep it in sync.
  42. //
  43. {
  44.     global string $gShelfTopLevel;
  45.     global string $gShelfCollection = "";
  46.  
  47.     setParent -m $parent;
  48.     menu -e -dai $parent;
  49.     $gShelfCollection = `radioMenuItemCollection`;
  50.  
  51.     // Shelf tab listing
  52.     string $curShelf = `tabLayout -q -selectTab $gShelfTopLevel`;
  53.     string $shelfArray[] = `shelfTabLayout -q -childArray $gShelfTopLevel`;
  54.     int $numShelves = size($shelfArray);
  55.  
  56.     for ($i=0; $i<$numShelves; ++$i) {
  57.         string $cmd = 
  58.             "shelfTabLayout -edit -selectTabIndex "+($i+1)+" "+$gShelfTopLevel+"; "
  59.             +"optionVar -iv selectedShelf `tabLayout -q -sti "+$gShelfTopLevel+"`";
  60.         int $enabled = ($shelfArray[$i] == $curShelf);
  61.         menuItem -ecr false -radioButton $enabled -cl $gShelfCollection
  62.             -l $shelfArray[$i] -c $cmd;
  63.     }            
  64. }
  65.  
  66. global proc shelfTabChange()
  67. //
  68. //    Description:
  69. //        This procedure is called whenever the user selects a new
  70. //        active shelf tab.
  71. //
  72. //        Update the active shelf preference.
  73. //
  74. {
  75.     global string $gShelfTopLevel;
  76.  
  77.     int $activeShelfTab;
  78.  
  79.     $activeShelfTab = `shelfTabLayout -query -selectTabIndex $gShelfTopLevel`;
  80.  
  81.     optionVar -intValue "selectedShelf" $activeShelfTab;
  82. }
  83.  
  84. global proc toggleShelfTabs ()
  85. {
  86.     global string $gShelfTopLevel;
  87.  
  88.     // Set optionVar to the opposite of the current state
  89.     int $newState = !`optionVar -q shelfTabsVisible`;
  90.     optionVar -intValue "shelfTabsVisible" $newState;
  91.     shelfTabLayout -e -tv $newState $gShelfTopLevel;
  92.  
  93.     setShelfStyle `optionVar -query shelfItemStyle`
  94.         `optionVar -query shelfItemSize`;
  95. }
  96.  
  97. global proc buildShelves() {
  98.  
  99.     global string $gShelfTopLevel;
  100.     
  101.     setParent $gShelfTopLevel;
  102.     
  103.     //    Define a template for shelf layouts.
  104.     //
  105.     if (!`uiTemplate -exists shelfLayoutTemplate`) {
  106.         uiTemplate shelfLayoutTemplate;
  107.         shelfLayout -dt shelfLayoutTemplate -h 34 -cwh 34 34;
  108.     }
  109.  
  110.     //    Activate the shelf layout template.
  111.     //
  112.     setUITemplate -pushTemplate shelfLayoutTemplate;
  113.  
  114.     string $varName, $cmd, $shelfFile, $shelfName;
  115.     int $i, $nShelves;
  116.  
  117.     $nShelves = `optionVar -q numShelves`;
  118.     int $isFile;
  119.     for ($i = 1; $i <= $nShelves; $i++) {
  120.         $varName = ("shelfName" + $i);
  121.         $shelfName = `optionVar -q $varName`;
  122.  
  123.         $cmd = ("shelfLayout " + $shelfName);
  124.         eval $cmd;
  125.  
  126.         $varName = ("shelfFile" + $i);
  127.         $shelfFile = `optionVar -q $varName`;
  128.         if ($shelfFile != 0) {
  129.             $isFile = `exists $shelfFile`;
  130.             if ($isFile != 0) {
  131.  
  132. // If we use evalContinue then we aren't notified if there are any errors
  133. //                evalContinue $shelfFile;
  134.  
  135.                 if (catch(eval($shelfFile))) {
  136.                     string $returnStr;
  137.                     string $msg = 
  138.                          "The shelf \""+$shelfName+"\" has items that cannot be read.\n"
  139.                         +"The shelf will only display the items before the first unreadable item it finds.\n"
  140.                         +"If you start Maya and save this shelf then you will lose the unreadable items.\n"
  141.                         +"This will happen automatically if you have your preferences set to save the shelves on exit.";
  142.                     $returnStr = `confirmDialog -title "Shelf Error" 
  143.                         -message $msg
  144.                         -button "Continue" 
  145.                         -button "Quit Maya"`;
  146.                     if ("Quit Maya" == $returnStr) {
  147.                         quit -f;
  148.                     }
  149.                 }
  150.             }
  151.         }            
  152.  
  153.         setParent ..;
  154.     }
  155.  
  156.     //    Deactivate the shelf layout template.
  157.     //
  158.     setUITemplate -popTemplate;
  159.  
  160.     //    Define the default active shelf if a preference does not
  161.     //    exist yet.
  162.     //
  163.     if (!`optionVar -exists "selectedShelf"`) {
  164.         // Maya Personal Learning Edition should default to showing
  165.         // the General Tab for brand-new users.
  166.         //
  167.         if (`about -windows` && (!`about -evalVersion`) ) {
  168.             optionVar -intValue "selectedShelf" 4;
  169.         } else {
  170.             optionVar -intValue "selectedShelf" 1;
  171.         }
  172.     }
  173.  
  174.     //    Get the selected tab preference and make that shelf tab active.
  175.     //
  176.     int $activeTab = `optionVar -query "selectedShelf"`;
  177.  
  178.     //    Make sure the tab preference is valid given the number of
  179.     //    tabs in the shelf, ie. it should be a number ranging from
  180.     //    1 to the number of tabs in the shelf.
  181.     //
  182.     if ($activeTab < 1
  183.         || $activeTab > `tabLayout -query -numberOfChildren $gShelfTopLevel`) {
  184.         //
  185.         //    The active tab preference is not valid given the number
  186.         //    of tabs in the Shelf.
  187.         //
  188.         //    Reset the preference to the first shelf tab.
  189.         //
  190.         $activeTab = 1;
  191.         optionVar -intValue "selectedShelf" $activeTab;
  192.     }
  193.  
  194.     tabLayout -edit -selectTabIndex $activeTab $gShelfTopLevel;
  195.  
  196.     //    Set the display style for the buttons on the Shelf.
  197.     //
  198.     setShelfStyle `optionVar -query shelfItemStyle` 
  199.                   `optionVar -query shelfItemSize`;
  200. }
  201.  
  202. {
  203.     global string $gShelfForm;
  204.     global string $gShelfTopLevel;
  205.  
  206.     int $bottomSpacing;
  207.  
  208.     //    Create a layout appropriate for the Shelf.
  209.     //
  210.     string $shelfLayout = `formLayout -parent $gShelfForm`;
  211.  
  212.     //////////////////////////////////////////////////////////////////////
  213.     //
  214.     //    Create the Menu and Options area.
  215.     //
  216.     //////////////////////////////////////////////////////////////////////
  217.  
  218.     setParent $shelfLayout; 
  219.  
  220.     string $options = `frameLayout
  221.         -parent         $shelfLayout
  222.         -borderVisible  true
  223.         -borderStyle    "in"
  224.         -labelVisible   false
  225.         -collapse       false
  226.         -collapsable    false`;    
  227.  
  228.     string $optionsLayout = `formLayout`;
  229.  
  230.     string $shelvesButton = `iconTextButton
  231.         -image1 "shelfTab.xpm" 
  232.         -annotation "Change which shelf tab is displayed"
  233.         -height 15 -width 20`;
  234.     
  235.     string $shelvesSeparator = `separator`;
  236.  
  237.     string $optionsButton = `iconTextStaticLabel
  238.         -image1 "shelfOptions.xpm" 
  239.         -annotation "Menu of items to modify the shelf"
  240.         -height 16 -width 20`;
  241.  
  242.     setParent ..;
  243.  
  244.     //    For improving the alignment of shelves buttons.
  245.     //
  246.     if (`about -nt`) {
  247.         $bottomSpacing = 0;
  248.     } else {
  249.         $bottomSpacing = 1;
  250.     }
  251.  
  252.     formLayout -edit
  253.         -attachNone     $shelvesButton    "top"
  254.         -attachForm     $shelvesButton    "left"   0
  255.         -attachControl  $shelvesButton    "bottom" $bottomSpacing $shelvesSeparator
  256.         -attachForm     $shelvesButton    "right"  0
  257.  
  258.         -attachNone     $shelvesSeparator "top"
  259.         -attachForm     $shelvesSeparator "left"   0
  260.         -attachControl  $shelvesSeparator "bottom" 0 $optionsButton
  261.         -attachForm     $shelvesSeparator "right"  0
  262.  
  263.         -attachNone     $optionsButton    "top"
  264.         -attachForm     $optionsButton    "left"   0
  265.         -attachForm     $optionsButton    "bottom" 0
  266.         -attachForm     $optionsButton    "right"  0
  267.         $optionsLayout;
  268.     
  269.     //    Get the tab visible state.
  270.     //
  271.     if (!`optionVar -exists "shelfTabsVisible"`) {
  272.         //
  273.         //    The shelf tabs are visible for Windows only.
  274.         //
  275.         int $visible = false;
  276.         if (`about -windows`) {
  277.             $visible = true;
  278.         }
  279.         optionVar -intValue "shelfTabsVisible" $visible;
  280.     }
  281.     int $tabVis = `optionVar -q shelfTabsVisible`;
  282.  
  283.     // Create the tab-switching menu
  284.     //
  285.     string $menu = `popupMenu -button 1 -parent $shelvesButton`;
  286.     menu -edit -postMenuCommand ( "buildShelfMenu " + $menu ) $menu;
  287.  
  288.     // Create the options menu
  289.     //
  290.     $menu = `popupMenu -button 1 -parent $optionsButton`;
  291.     menuItem -ecr false -cb $tabVis -c "toggleShelfTabs" -l "Shelf Tabs";
  292.     menuItem -d true;
  293.     menuItem -ecr false -l "Shelf Editor..." -c "shelfEditorDialog";
  294.     menuItem -d true;
  295.     menuItem -ecr false -l "New Shelf" -c "createNewShelf";
  296.     string $cmd = "deleteShelfTab(`tabLayout -q -selectTab $gShelfTopLevel`);";
  297.     menuItem -ecr false -l "Delete Shelf" -c $cmd;
  298.     menuItem -d true;
  299.     menuItem -ecr false -l "Load Shelf..." -c "loadNewShelf \"\"";
  300.     menuItem -d true;
  301.     menuItem -ecr false -l "Save All Shelves" -c "saveAllShelves $gShelfTopLevel";
  302.     
  303.     //////////////////////////////////////////////////////////////////////
  304.     //
  305.     //    Create the Shelf.
  306.     //
  307.     //////////////////////////////////////////////////////////////////////
  308.     $gShelfTopLevel = `shelfTabLayout
  309.         -parent        $shelfLayout 
  310.         -tabsVisible   $tabVis
  311.         -image         "smallTrash.xpm" 
  312.         -imageVisible  true
  313.         -changeCommand ("shelfTabChange")
  314.         ShelfLayout`;
  315.  
  316.     //    For improving the alignment of options buttons.
  317.     //
  318.     if (`about -nt`) {
  319.         $bottomSpacing = 1;
  320.     } else {
  321.         $bottomSpacing = 0;
  322.     }
  323.  
  324.     //    Layout Shelf.
  325.     //
  326.     formLayout -edit
  327.         -attachNone        $options          "top"
  328.         -attachForm     $options          "left"    2
  329.         -attachForm        $options          "bottom"    $bottomSpacing
  330.         -attachNone        $options          "right"
  331.  
  332.         -attachForm        $gShelfTopLevel   "top"    0
  333.         -attachControl    $gShelfTopLevel   "left"   0 $options
  334.         -attachForm        $gShelfTopLevel   "bottom" 0
  335.         -attachForm        $gShelfTopLevel   "right"  0
  336.         $shelfLayout;
  337.  
  338.     //    Attach Shelf to parent.
  339.     //
  340.     formLayout -edit
  341.         -attachForm $shelfLayout "top"    0
  342.         -attachForm $shelfLayout "left"   0
  343.         -attachForm $shelfLayout "bottom" 0
  344.         -attachForm $shelfLayout "right"  0
  345.         $gShelfForm;
  346. }
  347.  
  348.